package com.kuang.servlet;

import com.kuang.pojo.Person;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class SessionServlet01 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html; charset=UTF-8");
        HttpSession session =req.getSession();
        session.setAttribute("name",new Person("秦疆",23));
        String sessionId=session.getId();
        if(session.isNew()){
            resp.getWriter().write("session创建成功："+sessionId);
        }else {
            resp.getWriter().write("session在服务器中存在："+ sessionId);
        }
    }
}
